#ifndef TREE_H_
#define TREE_H_
#include <cstdint>
#include <cmath>
#include <utility>
#include <iostream>
#include <stdio.h>
#include "pxl.h"
#include "suan_png.h"
#include<vector>
struct color_inf
{
    int r,g,b;
};

class Node {
private:
    PNG *p; //the upper left pixel
    Node **children; //pointer to four other node
    int width; //当前像素区块的宽度
    int height; //当前像素区块的高度
    bool leaf; //是否是叶子节点，true 代表是叶子节点
    int x; //当前像素区块左上角顶点像素的横坐标
    int y; //当前像素区块左上角顶点像素的纵坐标
    int mean_r; //Rmean
    int mean_g; //Gmean
    int mean_b; //Bmean
public:
    int cut_count;
    bool cut_flag;
    bool have_two;
    Node();
    Node(PNG* corner, int input_width, int input_height, int x, int y);
    Node(Node &other);
    Node(Node &&other);
    Node& operator=(Node &other);
    Node& operator=(Node &&other);
    ~Node();
    void print();
    pxl *get_pxl();
    Node** get_children();
    void set_color(uint8_t,uint8_t,uint8_t);
    color_inf get_color();
    int get_width();
    int get_height();
    PNG* get_png();
    void set_color_to_pxls(PNG*,uint8_t,uint8_t,uint8_t,int);
    int get_x();
    int get_y();
    
    
    
};


class Tree {
private:
    Node *root; //根结点
    PNG *orgin_png;
public:
    Tree();
    ~Tree();
    Tree(Tree &other);
    Tree& operator=(Tree &other);
    void judge(int threshold);
    pxl *get_pxl();
    void load_png(PNG *png);
    void print();
    //void create_tree(Node *this_node,PNG* png,int width,int height,int x,int y);
    std::vector<Node*> get_children_list(Node* this_root);
    void DFS(Node* this_root,int);
    bool check_cut_count(Node* this_node);
    void cut(Node*,uint8_t,uint8_t,uint8_t);
    void fresh_mean(Node*);
    void create_tree(Node *this_node,PNG* png,int width,int height,int x,int y);
    bool check_cut(Node* this_node);
};
#endif
